package com.example.controller;

import com.example.domain.Mainzone;
import com.example.domain.Result;
import com.example.domain.Zone;
import com.example.service.MainzoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mainzones")
public class MainzoneController {

    @Autowired
    private MainzoneService mainzoneService;

    @GetMapping
    public Result getAll(){
        return new Result(true,mainzoneService.getAll());
    }

    @GetMapping("{mainzoneId}")
    public Result getById(@PathVariable Integer mainzoneId){
        return new Result(true,mainzoneService.getById(mainzoneId));
    }

    @PostMapping
    public Result add(@RequestBody Mainzone mainzone) {
        boolean code = mainzoneService.add(mainzone);
        return new Result(code);
    }

    @PutMapping
    public Result update(@RequestBody Mainzone mainzone){
        boolean code = mainzoneService.update(mainzone);
        return new Result(code);
    }

    @DeleteMapping("{mainzoneId}")
    public Result delete(@PathVariable Integer mainzoneId){
        boolean code = mainzoneService.delete(mainzoneId);
        return new Result(code);
    }

}
